//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package org.jim.server.command.handler;

import org.jim.core.ImChannelContext;
import org.jim.core.ImPacket;
import org.jim.core.exception.ImException;
import org.jim.core.packets.BusinessBody;
import org.jim.core.packets.Command;
import org.jim.core.packets.GpsBody;
import org.jim.core.packets.RespBody;
import org.jim.core.utils.JsonKit;
import org.jim.server.JimServerAPI;
import org.jim.server.command.AbstractCmdHandler;
import org.jim.server.processor.business.BusinessCmdProcessor;
import org.jim.server.processor.gps.GpsCmdProcessor;
import org.jim.server.protocol.ProtocolManager;

import static org.jim.core.packets.Command.*;

public class BusinessReqHandler extends AbstractCmdHandler {
    public BusinessReqHandler() {
    }

    public ImPacket handler(ImPacket packet, ImChannelContext channelContext) throws ImException {
        if (packet.getBody() == null) {
            throw new ImException("body is null");
        } else {
            BusinessBody businessBody = JsonKit.toBean(packet.getBody(), BusinessBody.class);
            BusinessCmdProcessor businessCmdProcessor = this.getSingleProcessor(BusinessCmdProcessor.class);
            businessCmdProcessor.process(businessBody, channelContext);
            return ProtocolManager.Converter.respPacket(new RespBody(COMMAND_BUSINESS_RESP), channelContext);
        }
    }

    public Command command() {
        return Command.COMMAND_BUSINESS_REQ;
    }
}
